package ssi.beans;



import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.struts.action.ActionForm;



import ssi.tools.Type;
import ssi.tools.Connector;


public class User extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String name;
	private String email = "";
	private String password;
	private String surname;
	private String address;
	private Type typeOfUser;
	private String pesel;
	private String animalID;

	

	public String getAnimalID() {
		return animalID;
	}

	public void setAnimalID(String animalID) {
		this.animalID = animalID;
	}

	public User() {

	}

	public User(int id, String email, String password, String typeOfUser,
			String name, String surname, String address) {
		this.id = id;
		this.email = email;
		this.password = password;
		this.typeOfUser = Type.valueOf(typeOfUser);
		this.name = name;
		this.surname = surname;
		this.address = address;
	}


	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Type getTypeOfUser() {
		return typeOfUser;
	}

	public void setTypeOfUser(Type typeOfUser) {
		this.typeOfUser = typeOfUser;
	}

	public String getUserName() {
		return email;
	}

	public void setUserName(String userName) {
		this.email = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getPesel() {
		return pesel;
	}

	public void setPesel(String pesel) {
		this.pesel = pesel;
	}
	
	public static String[] getUser(String id){
		String[] user=new String[4];
		try{
			Connection connection = new Connector().getConnection();
    		Statement statement = connection.createStatement();
			ResultSet result = statement.executeQuery("SELECT id,name,surname,email from users where id=" + id + "");
			while(result.next()){
				user[0]=result.getString("name");
				user[1]=result.getString("surname");
				user[2]=result.getString("email");;
				user[3]=result.getString("id");
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return user;
	}

}